package jwdt.web.action;

import java.util.List;
import java.util.Map;

import jwdt.common.util.StringUtil;
import jwdt.web.validate.OrderValidator;
import jwdt.xadmin.added.bean.TOpinion;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Interceptors;

public class ServiceAction extends BaseAction {
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Page doList(Form f, Module m) throws Exception {
		int rows = 1;
		int page = f.getInt("page", 1);
		int typeid = f.getInt("id");
		String where = " WHERE typeid = "+typeid+" and checked=1 ";
		String sql = select_news + where + order_news;
		PageUtil pu = new PageUtil("select count(*) from t_news "+where, sql, page, rows);
		List<Map> res = pu.getResult();
		for(Map re : res) {
			String content = (String)re.get("content");
			re.put("content", StringUtil.get().splitAndFilterHTML(content, 150));
		}
		return m.jsonPage(pu);
	}

	@Interceptors(OrderValidator.class)
	public Page execute(Form f, Module m) throws Exception{
		String ret = "提交成功！";
		TOpinion obj = (TOpinion)f.copy2Class(TOpinion.class);
		try{ 
			Jdb.get().add(obj);
		}catch(Exception e){
			ret = "提交出现问题，请稍候重新提交！";
		}
		f.add("ret", ret);
		//
		return m.findPage("tips");
	}
	
}
